package com.bytecodezz.jc.composetesting

import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Scaffold
import androidx.compose.runtime.Composable
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.ui.Modifier
import com.bytecodezz.jc.composetesting.ui.components.RallyTopAppBar
import com.bytecodezz.jc.composetesting.ui.theme.JetpackComposeTheme

class MainActivity : ComponentActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContent {
            RallyApp()
        }
    }
}


@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun RallyApp() {
    JetpackComposeTheme {
        val allScreens = RallyScreen.values().toList()
        var currentScreen = rememberSaveable { mutableStateOf(RallyScreen.Overview) }
        Scaffold(
            topBar = {
                RallyTopAppBar(
                    allScreens = allScreens,
                    onTabSelected = { screen -> currentScreen.value = screen },
                    currentScreen = currentScreen.value
                )
            }
        ) { innerPadding ->
            Box(Modifier.padding(innerPadding)) {
                currentScreen.value.content(onScreenChange = { screen ->
                    currentScreen.value = screen
                })
            }
        }
    }
}